<?php
require_once "base.php";

class Home extends Base {

	function Home() {
		parent :: Base();
	}

	function index($node_id = 1) {
		$this->_nodeid = $node_id;
		return $this->render("home/index", null);
	}

	function description() {
		return $this->renderdesc("home/description", null);
	}

	function news_detail($nav, $id){
		$this->_nodeid = $nav;
		return $this->render("template/content_news_detail", null);
	}
	
	function store_detail($nav, $id){
		$this->_nodeid = $nav;
		$this->_layout = "layout/store_layout.php";
		return $this->render("template/content_store_detail", null);
	}

	function showimage() {
		return $this->load->view("home/showimage.php");
	}

	function sitemap()
	{
		$this->load->model('Model_nav', 'model_nav');
		// set layout
		$this->_layout = "layout/inner_layout.php";
		return $this->renderdesc("template/content_sitemap_grid", null);
	}

	function search()
	{
		// Get model
		$keyword = $this->_keyword;
		$this->_layout = "layout/store_layout.php";
		return $this->render("search/result", array('keyword'=>$keyword));
	}

	function getNodeInfor() {
		// Response ajax
		$nodeinfo = parent :: processNode();
		header('Content-type: text/json');
		header('Pragma: public');
		header('Cache-control: private');
		header('Expires: -1');
		echo json_encode($nodeinfo);
		exit;
	}


	function downloaddata($id = 0) {
		if (intval ($id)) {
			// Get file name
			$this->load->model('Model_data', 'model_data');
			$data = $this->model_data->find($id);
			if(is_array($data)){
				$this->load->helper('download');
				$name = $data['name'];
				$name = str_replace(' ' , '_', $name);
				$filename = $data['filename'];
				$name .= substr($filename, strpos($filename, '.'));
				// Load config
				$path_download_file = $this->config->item('docs_upload_config');
				$path_download_file = $path_download_file['upload_path'];
				if(file_exists($path_download_file . FILE_SEPARATOR . $filename)){
					$data = file_get_contents($path_download_file . FILE_SEPARATOR . $filename); // Read the file's contents
				//echo $path_download_file . $filename;
					force_download($name, $data);
				}else{
					redirect(site_url(array('c'=>'home','m'=>'index')));
				}
			}
		}
		return;
	}

}
?>